# Deploying your own Sweep instance via Docker

We use the&nbsp;[Elastic License V2](https://www.elastic.co/licensing/elastic-license) which allows commercial usage for Sweep.
This is a guide for self-hosting Sweep. If you would like to use our hosted version, please visit https://github.com/apps/sweep-ai.

## 1. Downloading Sweep

Open [Docker Desktop](https://www.docker.com/products/docker-desktop/) and run the following code in your terminal (hover over code for copy button):

```sh filename="terminal"
git clone --depth 1 --single-branch https://github.com/sweepai/sweep
cd sweep
touch .env
docker compose pull
```

1. Clone the [sweepai/sweep](https://github.com/sweepai/sweep) repository
2. Create a `.env` file in the root directory
3. Pull the docker image.

In the `.env`, configure the repository that Sweep should work on.

```sh filename=".env"
REPO=your-username/your-repo
```

We're halfway done! Pulling the image will take a few minutes, so let's complete the next steps for now.

## 2. GitHub PAT
To allow Sweep to access your repo, create a new [GitHub Personal Access Token (PAT) here](https://github.com/settings/tokens/new?description=Sweep%20Self-hosted&scopes=repo,workflow). Sweep will run entirely locally, and no code will be shared outside of OpenAI's API.

Add this to your `.env` which should now look like this:

```sh filename=".env"
REPO=your-username/your-repo
GITHUB_PAT=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

<details>
<summary>
Link not working?
</summary>
If the link doesn't work, you can go [here](https://github.com/settings/tokens/new) and manually set your preferred token name (e.g. Sweep Self-Hosted), and select the following permissions:
* repo (ALL)
* workflow
</details>

## 3. OpenAI API Token

Please create an OpenAI API token at https://platform.openai.com/account/api-keys.
```sh
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

After following the above sections, your `.env` should look like this:
```sh filename=".env"
REPO=your-username/your-repo
GITHUB_PAT=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

<details>
<summary>
(Optional) Disabling Telemetry
</summary>
We log user events(not user code) to improve the product, such as the # of pull requests created and merged. To disable telemetry, you can add the following line to your `.env`:
```sh filename=".env"
POSTHOG_API_KEY=none
```
</details>

---

## 4. Deploying Sweep Locally

Once `docker compose pull` from Step 1 is complete, you can run Sweep locally with the following command:

```sh filename="terminal"
docker compose up # Add -d to run in background
```

## 5. Creating a Pull Request with Sweep

Finally, you can use Sweep by creating a new issue on the repository with a title prefixed with `Sweep:`, like `Sweep: add type hints to BaseIndex.tsx`!

For more details on using Sweep see [how to use Sweep](https://docs.sweep.dev/#-how-to-use-sweep).

**You have successfully deployed Sweep! 🚀**

---

### Alternative Deployment via GitHub App:
If you successfully deployed Sweep, you can skip this section.

You can self-deploy Sweep as a GitHub App to serve many repos at once. This is a more complicated process, but it is more scalable and is what we use for our hosted version. You can find the instructions [here](https://docs.sweep.dev/usage/self-hosting) or contact us at team@sweep.dev if you need help getting set up.
